@extends('layouts.header')
@section('title','短信购买记录')
@section('content')
    <nav class="breadcrumb">
        {{--<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 基础信息 <span class="c-gray en">&gt;</span> 微信通知管理--}}
        <a class="btn btn-primary radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);"
           title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <div class="page-container">
        <div class="cl pd-5 bg-1 bk-gray">
            <span class="">
{{--                <a href="javascript:;" onclick="add('添加微信通知规则','/{{config('constant.name_admin')}}/notice/sms/add','','430')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加微信通知规则</a>--}}
                <a href="javascript:;" class="btn btn-primary radius" id="buy"><i class="Hui-iconfont">&#xe732;</i> 添加 </a>
                <span class="ml-10">可用短信：{{$data['setting_sms']['count']}}条</span>
            </span>
        </div>
        <div class="mt-10">
            <table class="table table-border table-bordered table-hover table-bg table-responsive" id="datatable">
                <thead>
                <tr class="text-c">
                    <th>购买人</th>
                    <th>单价（分）</th>
                    <th>总金额（元）</th>
                    <th>短信条数</th>
                    <th>支付状态</th>
                    <th>发票代码</th>
                    <th>发票编号</th>
                    <th>开票时间</th>
                    <th>审核状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data['list'] as $item)
                    <tr class="text-c">
                        <td>{{$item->realname}}</td>
                        <td>{{$item->unit_price}}</td>
                        <td>{{$item->price}}</td>
                        <td>{{$item->sms_num}}</td>
                        <td>{{$item->is_paid == 1 ? '未支付' : '已支付'}}</td>
                        <td>{{$item->inv_code}}</td>
                        <td>{{$item->inv_no}}</td>
                        <td>{{$item->inv_date}}</td>
                        <td>{{$item->audit == 1 ? '未审核' : '已审核'}}</td>
                        <td class="text-l">
                            @if($item->audit == 1)
                                @if($item->is_paid == 2)
                                    <a class="btn btn-success radius size-MINI" onclick="audit('{{$item->id}}',2)">通过</a>
                                    <a class="btn btn-danger radius size-MINI" onclick="audit('{{$item->id}}',3)">驳回</a>
                                @elseif($item->is_paid == 1)
                                    <a class="btn btn-primary radius size-MINI" onclick="del('{{$item->id}}')">删除</a>
                                    <a class="btn btn-primary radius size-MINI" onclick="pay('{{$item->id}}')">支付</a>
                                @endif
                            @else
                                @if($item->audit == 2)
                                    <a class="btn btn-success radius size-MINI">已通过</a>
                                @elseif($item->audit == 3)
                                    <a class="btn btn-danger radius size-MINI">未通过</a>
                                @endif
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>


    <script type="text/javascript">
        var table;
        $(function () {
            $.fn.dataTable.ext.errMode = 'throw';//datatable抛异常的方式，在console中输出，默认以alert的方式弹出
            table = $('#datatable').DataTable({
                //order: [[ 6, 'desc' ]],//默认第几个排序
                ordering: false, // 是否排序
                // "deferRender": true,//延迟渲染速度
            });
            $('#buy').on('click', function () {
                layer_show('添加', 'add')
            })
        });


        $(document).on('click', '#showDetail', function () {
            let id = $(this).attr('data-id'), title = '短信发送详情', url = 'detail/' + id;
            layer_show(title, url);
        });

        /*删除*/
        function del(id) {
            var index2;

            layer.confirm('确认要删除吗？', {title: '信息', icon: 3}, function (index) {
                $.ajax({
                    type: 'GET',
                    url: '/{{config('constant.name_admin')}}/notice/sms/buy/del/' + id,
                    // dataType: 'json',
                    success: function (data) {
                        if (data === '1') {
                            layer.msg('删除成功!', {icon: 1, time: 2000});
                            location.replace(location.href);
                            // table_reload(0);//0停留在当前页，1回到第一页
                        } else {
                            layer.msg('删除失败!', {icon: 2, time: 2000});
                        }
                    },
                    error: function (data) {
                        ajax_error(data);
                    },
                    beforeSend: function () {
                        //0.4透明度 白色遮罩
                        index2 = layer.load(2, {shade: [0.05, '#000']});
                    },
                    complete: function () {
                        layer.close(index2);
                    },
                });
            });
        }

        /*支付*/
        function pay(id) {
            layer.msg('暂时仅支持联系业务购买短信！');
        }

        /*审核*/
        function audit(id, stat) {
            let str = stat == 2 ? '通过' : '驳回';
            layer.confirm('确认' + str + '吗？', {title: '审核', icon: 3}, function (index) {
                $.ajax({
                    type: 'GET',
                    url: '/{{config('constant.name_admin')}}/notice/sms/buy/audit/' + id + '/' + stat,
                    success: function (data) {
                        if (data > 0) {
                            layer.msg('审核成功!', {icon: 1, time: 2000});
                            location.replace(location.href);
                            // table_reload(0);//0停留在当前页，1回到第一页
                        } else {
                            layer.msg('审核失败!', {icon: 2, time: 2000});
                        }
                    },
                    error: function (data) {
                        ajax_error(data);
                    },
                    beforeSend: function () {
                        //0.4透明度 白色遮罩
                        index2 = layer.load(2, {shade: [0.05, '#000']});
                    },
                    complete: function () {
                        layer.close(index2);
                    },
                });
            });
        }


    </script>
@endsection
